<?php

class DomainRegistry
{

  /**
   *
   * @var array
   */
  protected static $reg = array();

  /**
   *
   * @return void
   */
  private function __construct()
  {
  }

  /**
   *
   * @param $name
   * @param $id
   * @return IDomObj
   */
  public static function get($name, $id)
  {
    return self::$reg[$name][$id];
  }

  /**
   *
   * @param $name
   * @param IDomObj $obj
   * @return IDomObj
   */
  public static function set(IDomObj $obj)
  {
    $name = $obj->getDefinition()->getName();

    if (! isset(self::$reg[$name])) {
      self::$reg[$name] = array();
    }

    $id = $obj->getId();

    self::$reg[$name][$id] = $obj;
  }

  /**
   *
   * @param $name
   * @param $id
   * @return boolean
   */
  public static function has($name, $id)
  {
    return isset(self::$reg[$name]) && isset(self::$reg[$name][$id]);
  }

}

?>